package com.example.cstr.controller;

import com.example.cstr.entity.Message;
import com.example.cstr.entity.Year;
import com.example.cstr.service.YearService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/Year")
@Api(tags = "年度")
public class YearController {
    @Resource
    private YearService yearService;

    @ApiOperation(value="添加年度")
    @PostMapping("/add")
    public Message insertYear(Year year){
        return yearService.insertSelective(year)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "删除年度")
    @DeleteMapping("/delete")
    public Message deleteYear(Integer yearId){
        return yearService.deleteByPrimaryKey(yearId)!=null?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "修改年度")
    @PutMapping("/update")
    public Message updateYear(Year year){
        return yearService.updateByPrimaryKeySelective(year)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value="根据年度id查询年度信息")
    @GetMapping("/select")
    public Message selectYear(Integer yearId){
        return yearService.selectByPrimaryKey(yearId)!=null?Message.success(null).add(yearService.selectByPrimaryKey(yearId)):Message.fail(null);
    }

    @ApiOperation(value = "查询所有年度信息")
    @GetMapping("/selectall")
    public Message selectAllYear(){
        return Message.success(null).add(yearService.selectAllYear());
    }

    @ApiOperation(value = "分页查询-查询所有年度信息")
    @GetMapping("/pagingSearch")
    public Message PagingSearch(@RequestParam Integer pageNum,@RequestParam Integer size){
        return yearService.PagingSearch(pageNum,size);
    }

    @ApiOperation(value = "获取当前年度信息")
    @GetMapping("/selectCurrentYear")
    public Message selectCurrentYear(){
        return yearService.selectCurrentYear()!=null?Message.success(null).add(yearService.selectCurrentYear()):Message.fail("未设置当前年度");
    }
}
